﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

using Microsoft.AnalysisServices.AdomdClient;

namespace KoOLAP_TestWinForms
{
    public class PlanProgress
    {
        public static Exception Get(ref DataTable tbl, string parConnStr, int parYear, int parMonth)
        {
            Exception ret = null;
            CellSet cst = null;
            string cmdStr1 =
@"
SELECT
HIERARCHIZE( { [Дата].[Месяцы].&[";
            string cmdStr2 =
@"] } ) * 
( { 
      [Номенклатура].[Секция].&[ИГРУШКИ]
    , [Номенклатура].[Секция].&[МЕБЕЛЬ]
    , [Номенклатура].[Секция].&[ОДЕЖДА]
    , [Номенклатура].[Секция].&[КОСМЕТИКА]
    , [Номенклатура].[Секция].&[ПОДГУЗНИКИ] 
    , [Номенклатура].[Секция].&[ДЕТСКОЕ ПИТАНИЕ]
    , [Номенклатура].[Секция].&[ОБУВЬ]
} )
ON COLUMNS,
{
    [Подразделение].[Подразделение].[Подразделение].ALLMEMBERS } 
    * 
    { 
          [Measures].[Оборот7 Руб]
        , [Measures].[План на месяц]
        , [Measures].[Прогноз7 руб]
        , [Measures].[Откл-е прогноза %] 
}
ON ROWS
FROM [KPI]
CELL PROPERTIES VALUE
, FORMATTED_VALUE
, CELL_ORDINAL
, FONT_FLAGS
, FORE_COLOR
, BACK_COLOR
";

            string datastr = string.Format("{0,4:0000}{1,2:00}", parYear, parMonth);
            string cmdStr = cmdStr1 + datastr + cmdStr2;

            Exception err = Exec(ref cst, parConnStr, cmdStr);

            if (err != null)
            {
                ret = new Exception(err.Message);
            }
            else
            {
                err = Parse(ref cst, ref tbl);
            }

            return ret;
        }

        public static Exception Get2(ref DataTable tbl, string parConnStr, int parYear, int parMonth)
        {
            Exception ret = null;
            CellSet cst = null;

            string cmdStr1 =
@"
SELECT
{
      [Measures].[Оборот7 Руб]
    , [Measures].[План на месяц]
    , [Measures].[Прогноз7 руб]
    , [Measures].[Откл-е прогноза %]
}
ON COLUMNS,
DISTINCT( HIERARCHIZE( { EXCEPT( { EXCEPT( { 
[Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr2 =
@"], [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr3 =
@"].CHILDREN }, { DESCENDANTS( 
[Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr4 =
@"], [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr5 =
@"].LEVEL, AFTER )
} ), [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr6 =
@"].CHILDREN }, 
{ DESCENDANTS( [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr7 =
@"]
, [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr8 =
@"].LEVEL, AFTER ) } ) } ) )
ON ROWS
FROM [KPI]
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, FONT_FLAGS, FORE_COLOR, BACK_COLOR
";

            string datastr = string.Format("{0,4:0000}{1,2:00}", parYear, parMonth);
            string cmdStr = cmdStr1 + datastr + cmdStr2 + datastr + cmdStr3 + datastr + cmdStr4 + datastr + cmdStr5 + datastr + cmdStr6 + datastr + cmdStr7 + datastr + cmdStr8;

            Exception err = Exec(ref cst, parConnStr, cmdStr);

            if (err != null)
            {
                ret = new Exception(err.Message);
            }
            else
            {
                err = Parse2(ref cst, ref tbl);
            }

            return ret;
        }

        public static Exception Get3(ref DataTable tbl, string parConnStr, int parYear, int parMonth)
        {
            Exception ret = null;
            CellSet cst = null;

            string cmdStr1 =
@"
SELECT
HIERARCHIZE( { 
      [Номенклатура].[Секция].&[ДЕТСКОЕ ПИТАНИЕ]
    , [Номенклатура].[Секция].&[ИГРУШКИ]
    , [Номенклатура].[Секция].&[КОСМЕТИКА]
    , [Номенклатура].[Секция].&[МЕБЕЛЬ]
    , [Номенклатура].[Секция].&[ОБУВЬ]
    , [Номенклатура].[Секция].&[ОДЕЖДА]
    , [Номенклатура].[Секция].&[ПОДГУЗНИКИ] } ) 
    * { [Measures].[Прогноз7 руб], [Measures].[Откл-е прогноза %] 
}
ON COLUMNS,
DISTINCT( HIERARCHIZE( { EXCEPT( { EXCEPT( { EXCEPT( { EXCEPT( 
{ [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr2 =
@"], [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr3 =
@"].CHILDREN }, { DESCENDANTS( [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr4 =
@"], [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr5 =
@"].LEVEL, AFTER ) } ), [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr6 =
@"].CHILDREN }, { DESCENDANTS( [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr7 =
@"], [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr8 =
@"].LEVEL, AFTER ) } ), [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr9 =
@"].CHILDREN }, { DESCENDANTS( [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr10 =
@"], [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr11 =
@"].LEVEL, AFTER ) } ), [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr12 =
@"].CHILDREN }, { DESCENDANTS( [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr13 =
@"], [Дата].[Г-М-Д].[Месяц].&[";
            string cmdStr14 =
@"].LEVEL, AFTER ) } ) } ) )
ON ROWS
FROM [KPI]
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, FONT_FLAGS, FORE_COLOR, BACK_COLOR
";

            string datastr = string.Format("{0,4:0000}{1,2:00}", parYear, parMonth);
            string cmdStr = cmdStr1 + datastr + cmdStr2 + datastr + cmdStr3 + datastr + cmdStr4 + datastr + cmdStr5 + datastr + cmdStr6 + datastr + cmdStr7 + datastr + cmdStr8 + datastr + cmdStr9 + datastr + cmdStr10 + datastr + cmdStr11 + datastr + cmdStr12 + datastr + cmdStr13 + datastr + cmdStr14;

            Exception err = Exec(ref cst, parConnStr, cmdStr);

            if (err != null)
            {
                ret = new Exception(err.Message);
            }
            else
            {
                err = Parse3(ref cst, ref tbl);
            }

            return ret;
        }

        public static Exception Get4(ref DataTable tbl, string parConnStr, string parShopName, int parYear, int parMonth)
        {
            Exception ret = null;
            CellSet cst = null;
/*
SELECT
HIERARCHIZE( { [Дата].[Месяцы].&[201111] } ) 
ON COLUMNS,
{
    [Подразделение].[Подразделение].[Подразделение].[Александров] } 
    * 
    { 
            [Measures].[Оборот7 Руб]
        , [Measures].[План на месяц]
        , [Measures].[Прогноз7 руб]
        , [Measures].[Откл-е прогноза %] 
}
ON ROWS
FROM [KPI] 
CELL PROPERTIES VALUE
, FORMATTED_VALUE
, CELL_ORDINAL
, FONT_FLAGS
, FORE_COLOR
, BACK_COLOR
*/
            string cmdStr1 =
@"
SELECT
HIERARCHIZE( { [Дата].[Месяцы].&[";
            string cmdStr2 =
@"] } ) 
ON COLUMNS,
{
    [Подразделение].[Подразделение].[Подразделение].[";
            string cmdStr3 =
@"] } 
    * 
    { 
          [Measures].[Оборот7 Руб]
        , [Measures].[План на месяц]
        , [Measures].[Прогноз7 руб]
        , [Measures].[Откл-е прогноза %] 
}
ON ROWS
FROM [KPI]
CELL PROPERTIES VALUE
, FORMATTED_VALUE
, CELL_ORDINAL
, FONT_FLAGS
, FORE_COLOR
, BACK_COLOR
";

            string datastr = string.Format("{0,4:0000}{1,2:00}", parYear, parMonth);
            string cmdStr = cmdStr1 + datastr + cmdStr2 + parShopName + cmdStr3;

            Exception err = Exec(ref cst, parConnStr, cmdStr);

            if (err != null)
            {
                ret = new Exception(err.Message);
            }
            else
            {
                err = Parse4(ref cst, ref tbl);
            }

            return ret;
        }

        public static Exception Exec(ref CellSet parCst, string parConnStr, string parCmdStr)
        {
            Exception ret = null;
            try
            {
                using (AdomdConnection conn = new AdomdConnection(parConnStr))
                {
                    conn.Open();
                    using (AdomdCommand cmd = new AdomdCommand(parCmdStr, conn))
                    {
                        parCst = cmd.ExecuteCellSet();
                        conn.Close();
                    }
                }
            }
            catch (Exception err)
            {
                parCst = null;
                ret = new Exception(err.Message, err);
            }

            return ret;
        }

        public static Exception Parse(ref CellSet parCst, ref DataTable parTbl)
        {
            Exception ret = null;

            MakeTbl(ref parTbl);

            // check if any axes were returned else throw error.
            int axes_count = parCst.Axes.Count;
            if (axes_count == 0)
                return new Exception("No data returned for the selection");

            // if axes count is not 2
            if (axes_count != 2)
                return new Exception("The sample code support only queries with two axes");

            // if no position on either row or column throw error
            if (!(parCst.Axes[0].Positions.Count > 0) && !(parCst.Axes[1].Positions.Count > 0))
                return new Exception("No data returned for the selection");

            #region Members

            int cur_row, cur_col, col_count, row_count, col_dim_count, row_dim_count;
            cur_row = cur_col = col_count = row_count = col_dim_count = row_dim_count = 0;

            // Number of dimensions on the column
            col_dim_count = parCst.Axes[0].Positions[0].Members.Count;

            // Number of dimensions on the row
            if (parCst.Axes[1].Positions[0].Members.Count > 0)
                row_dim_count = parCst.Axes[1].Positions[0].Members.Count;

            // Total rows and columns
            row_count = parCst.Axes[1].Positions.Count + col_dim_count;  //number of rows + rows for column headers
            col_count = parCst.Axes[0].Positions.Count + row_dim_count;  //number of columns + columns for row headers

            int count = 0;
            DataRow r = null;

            #endregion

            for (cur_row = 0; cur_row < row_count - 2; cur_row++)
            {

                count++;
                if (count >= 5)
                    count = 1;
                if (count == 1)
                    r = parTbl.NewRow();

                string strShopName = parCst.Axes[1].Positions[cur_row].Members[0].Caption;
                string strValueType = parCst.Axes[1].Positions[cur_row].Members[1].Caption;
                string strMonth = "";

                try
                {
                    strMonth = parCst.Axes[0].Positions[cur_row].Members[0].Caption;
                }
                catch
                {
                }

                #region Data

                Decimal val1 = Convert.ToDecimal(parCst[0, cur_row].Value);
                Decimal val2 = Convert.ToDecimal(parCst[1, cur_row].Value);
                Decimal val3 = Convert.ToDecimal(parCst[2, cur_row].Value);
                Decimal val4 = Convert.ToDecimal(parCst[3, cur_row].Value);
                Decimal val5 = Convert.ToDecimal(parCst[4, cur_row].Value);
                Decimal val6 = Convert.ToDecimal(parCst[5, cur_row].Value);
                Decimal val7 = Convert.ToDecimal(parCst[6, cur_row].Value);

                if (count == 1)
                {
                    r["name"] = strShopName;
                    r["cell_1_1"] = val1;
                    r["cell_2_1"] = val2;
                    r["cell_3_1"] = val3;
                    r["cell_4_1"] = val4;
                    r["cell_5_1"] = val5;
                    r["cell_6_1"] = val6;
                    r["cell_7_1"] = val7;
                    r["cell_t_1"] = val1 + val2 + val3 + val4 + val5 + val6 + val7;
                }

                if (count == 2)
                {
                    r["name"] = strShopName;
                    r["cell_1_2"] = val1;
                    r["cell_2_2"] = val2;
                    r["cell_3_2"] = val3;
                    r["cell_4_2"] = val4;
                    r["cell_5_2"] = val5;
                    r["cell_6_2"] = val6;
                    r["cell_7_2"] = val7;
                    r["cell_t_2"] = val1 + val2 + val3 + val4 + val5 + val6 + val7;
                }

                if (count == 3)
                {
                    r["name"] = strShopName;
                    r["cell_1_3"] = val1;
                    r["cell_2_3"] = val2;
                    r["cell_3_3"] = val3;
                    r["cell_4_3"] = val4;
                    r["cell_5_3"] = val5;
                    r["cell_6_3"] = val6;
                    r["cell_7_3"] = val7;
                    r["cell_t_3"] = val1 + val2 + val3 + val4 + val5 + val6 + val7;
                }

                if (count == 4)
                {
                    r["name"] = strShopName;
                    r["cell_1_4"] = val1;
                    r["cell_2_4"] = val2;
                    r["cell_3_4"] = val3;
                    r["cell_4_4"] = val4;
                    r["cell_5_4"] = val5;
                    r["cell_6_4"] = val6;
                    r["cell_7_4"] = val7;
                    r["cell_t_4"] = val1 + val2 + val3 + val4 + val5 + val6 + val7;
                    parTbl.Rows.Add(r);
                }

                #endregion

            }

            return ret;
        }

        public static Exception Parse2(ref CellSet parCst, ref DataTable parTbl)
        {
            Exception ret = null;

            MakeTbl2(ref parTbl);

            #region Error

            // check if any axes were returned else throw error.
            int axes_count = parCst.Axes.Count;
            if (axes_count == 0)
                return new Exception("No data returned for the selection");

            // if axes count is not 2
            if (axes_count != 2)
                return new Exception("The sample code support only queries with two axes");

            // if no position on either row or column throw error
            if (!(parCst.Axes[0].Positions.Count > 0) && !(parCst.Axes[1].Positions.Count > 0))
                return new Exception("No data returned for the selection");

            #endregion

            #region Members

            int cur_row, cur_col, col_count, row_count, col_dim_count, row_dim_count;
            cur_row = cur_col = col_count = row_count = col_dim_count = row_dim_count = 0;

            // Number of dimensions on the column
            col_dim_count = parCst.Axes[0].Positions[0].Members.Count;

            // Number of dimensions on the row
            if (parCst.Axes[1].Positions[0].Members.Count > 0)
                row_dim_count = parCst.Axes[1].Positions[0].Members.Count;

            // Total rows and columns
            row_count = parCst.Axes[1].Positions.Count + col_dim_count;  //number of rows + rows for column headers
            col_count = parCst.Axes[0].Positions.Count + row_dim_count;  //number of columns + columns for row headers

            int count = 0;
            DataRow r = null;

            #endregion

            for (cur_row = 1; cur_row < row_count; cur_row++)
            {
                count++;
                r = parTbl.NewRow();

                Decimal val1 = Convert.ToDecimal(parCst[0, 0].Value);
                Decimal val2 = Convert.ToDecimal(parCst[1, 0].Value);
                Decimal val3 = Convert.ToDecimal(parCst[2, 0].Value);
                Decimal val4 = Convert.ToDecimal(parCst[3, 0].Value);

                r["name"] = "";
                r["cell_1"] = val1;
                r["cell_2"] = val2;
                r["cell_3"] = val3;
                r["cell_4"] = val4;

                parTbl.Rows.Add(r);
            }

            return ret;
        }

        public static Exception Parse3(ref CellSet parCst, ref DataTable parTbl)
        {
            Exception ret = null;

            MakeTbl3(ref parTbl);

            #region Error

            // check if any axes were returned else throw error.
            int axes_count = parCst.Axes.Count;
            if (axes_count == 0)
                return new Exception("No data returned for the selection");

            // if axes count is not 2
            if (axes_count != 2)
                return new Exception("The sample code support only queries with two axes");

            // if no position on either row or column throw error
            if (!(parCst.Axes[0].Positions.Count > 0) && !(parCst.Axes[1].Positions.Count > 0))
                return new Exception("No data returned for the selection");

            #endregion

            #region Members

            int cur_row, cur_col, col_count, row_count, col_dim_count, row_dim_count;
            cur_row = cur_col = col_count = row_count = col_dim_count = row_dim_count = 0;

            // Number of dimensions on the column
            col_dim_count = parCst.Axes[0].Positions[0].Members.Count;

            // Number of dimensions on the row
            if (parCst.Axes[1].Positions[0].Members.Count > 0)
                row_dim_count = parCst.Axes[1].Positions[0].Members.Count;

            // Total rows and columns
            row_count = parCst.Axes[1].Positions.Count + col_dim_count;  //number of rows + rows for column headers
            col_count = parCst.Axes[0].Positions.Count + row_dim_count;  //number of columns + columns for row headers

            int count = 0;
            DataRow r = null;

            #endregion

            for (cur_row = 2; cur_row < 3; cur_row++)
            {
                count++;
                r = parTbl.NewRow();

                Decimal val1_1 = Convert.ToDecimal(parCst[0, 0].Value);
                Decimal val1_2 = Convert.ToDecimal(parCst[1, 0].Value);
                Decimal val2_1 = Convert.ToDecimal(parCst[2, 0].Value);
                Decimal val2_2 = Convert.ToDecimal(parCst[3, 0].Value);
                Decimal val3_1 = Convert.ToDecimal(parCst[4, 0].Value);
                Decimal val3_2 = Convert.ToDecimal(parCst[5, 0].Value);
                Decimal val4_1 = Convert.ToDecimal(parCst[6, 0].Value);
                Decimal val4_2 = Convert.ToDecimal(parCst[7, 0].Value);
                Decimal val5_1 = Convert.ToDecimal(parCst[8, 0].Value);
                Decimal val5_2 = Convert.ToDecimal(parCst[9, 0].Value);
                Decimal val6_1 = Convert.ToDecimal(parCst[10, 0].Value);
                Decimal val6_2 = Convert.ToDecimal(parCst[11, 0].Value);
                Decimal val7_1 = Convert.ToDecimal(parCst[12, 0].Value);
                Decimal val7_2 = Convert.ToDecimal(parCst[13, 0].Value);

                r["name"] = "";
                r["cell_1_1"] = val1_1;
                r["cell_1_2"] = val1_2;
                r["cell_2_1"] = val2_1;
                r["cell_2_2"] = val2_2;
                r["cell_3_1"] = val3_1;
                r["cell_3_2"] = val3_2;
                r["cell_4_1"] = val4_1;
                r["cell_4_2"] = val4_2;
                r["cell_5_1"] = val5_1;
                r["cell_5_2"] = val5_2;
                r["cell_6_1"] = val6_1;
                r["cell_6_2"] = val6_2;
                r["cell_7_1"] = val7_1;
                r["cell_7_2"] = val7_2;

                parTbl.Rows.Add(r);
            }

            return ret;
        }

        public static Exception Parse4(ref CellSet parCst, ref DataTable parTbl)
        {
            Exception ret = null;

            MakeTbl(ref parTbl);

            // check if any axes were returned else throw error.
            int axes_count = parCst.Axes.Count;
            if (axes_count == 0)
                return new Exception("No data returned for the selection");

            // if axes count is not 2
            if (axes_count != 2)
                return new Exception("The sample code support only queries with two axes");

            // if no position on either row or column throw error
            if (!(parCst.Axes[0].Positions.Count > 0) && !(parCst.Axes[1].Positions.Count > 0))
                return new Exception("No data returned for the selection");

            #region Members

            int cur_row, cur_col, col_count, row_count, col_dim_count, row_dim_count;
            cur_row = cur_col = col_count = row_count = col_dim_count = row_dim_count = 0;

            // Number of dimensions on the column
            col_dim_count = parCst.Axes[0].Positions[0].Members.Count;

            // Number of dimensions on the row
            if (parCst.Axes[1].Positions[0].Members.Count > 0)
                row_dim_count = parCst.Axes[1].Positions[0].Members.Count;

            // Total rows and columns
            row_count = parCst.Axes[1].Positions.Count + col_dim_count;  //number of rows + rows for column headers
            col_count = parCst.Axes[0].Positions.Count + row_dim_count;  //number of columns + columns for row headers

            int count = 0;
            DataRow r = null;

            #endregion

            for (cur_row = 0; cur_row < row_count - 2; cur_row++)
            {

                count++;
                if (count >= 5)
                    count = 1;
                if (count == 1)
                    r = parTbl.NewRow();

                string strShopName = parCst.Axes[1].Positions[cur_row].Members[0].Caption;
                string strValueType = parCst.Axes[1].Positions[cur_row].Members[1].Caption;
                string strMonth = "";

                try
                {
                    strMonth = parCst.Axes[0].Positions[cur_row].Members[0].Caption;
                }
                catch
                {
                }

                #region Data

                Decimal val1 = Convert.ToDecimal(parCst[0, 0].Value);
                Decimal val2 = Convert.ToDecimal(parCst[0, 1].Value);
                Decimal val3 = Convert.ToDecimal(parCst[0, 2].Value);
                Decimal val4 = Convert.ToDecimal(parCst[0, 3].Value);

                if (count == 1)
                {
                    r["name"] = strShopName;
                    r["cell_1_1"] = val1;
                    r["cell_1_2"] = val2;
                    r["cell_1_3"] = val3;
                    r["cell_1_4"] = val4;
                    parTbl.Rows.Add(r);
                }

                break;

                #endregion

            }

            return ret;
        }

        public static void MakeTbl(ref DataTable parTbl)
        {
            if (parTbl == null)
                parTbl = new DataTable();

            parTbl.Columns.Add("name", typeof(String));

            parTbl.Columns.Add("cell_1_1", typeof(Decimal));
            parTbl.Columns.Add("cell_1_2", typeof(Decimal));
            parTbl.Columns.Add("cell_1_3", typeof(Decimal));
            parTbl.Columns.Add("cell_1_4", typeof(Decimal));

            parTbl.Columns.Add("cell_2_1", typeof(Decimal));
            parTbl.Columns.Add("cell_2_2", typeof(Decimal));
            parTbl.Columns.Add("cell_2_3", typeof(Decimal));
            parTbl.Columns.Add("cell_2_4", typeof(Decimal));

            parTbl.Columns.Add("cell_3_1", typeof(Decimal));
            parTbl.Columns.Add("cell_3_2", typeof(Decimal));
            parTbl.Columns.Add("cell_3_3", typeof(Decimal));
            parTbl.Columns.Add("cell_3_4", typeof(Decimal));

            parTbl.Columns.Add("cell_4_1", typeof(Decimal));
            parTbl.Columns.Add("cell_4_2", typeof(Decimal));
            parTbl.Columns.Add("cell_4_3", typeof(Decimal));
            parTbl.Columns.Add("cell_4_4", typeof(Decimal));

            parTbl.Columns.Add("cell_5_1", typeof(Decimal));
            parTbl.Columns.Add("cell_5_2", typeof(Decimal));
            parTbl.Columns.Add("cell_5_3", typeof(Decimal));
            parTbl.Columns.Add("cell_5_4", typeof(Decimal));

            parTbl.Columns.Add("cell_6_1", typeof(Decimal));
            parTbl.Columns.Add("cell_6_2", typeof(Decimal));
            parTbl.Columns.Add("cell_6_3", typeof(Decimal));
            parTbl.Columns.Add("cell_6_4", typeof(Decimal));

            parTbl.Columns.Add("cell_7_1", typeof(Decimal));
            parTbl.Columns.Add("cell_7_2", typeof(Decimal));
            parTbl.Columns.Add("cell_7_3", typeof(Decimal));
            parTbl.Columns.Add("cell_7_4", typeof(Decimal));

            parTbl.Columns.Add("cell_t_1", typeof(Decimal));
            parTbl.Columns.Add("cell_t_2", typeof(Decimal));
            parTbl.Columns.Add("cell_t_3", typeof(Decimal));
            parTbl.Columns.Add("cell_t_4", typeof(Decimal));


        }

        public static void MakeTbl2(ref DataTable parTbl)
        {

            if (parTbl == null)
                parTbl = new DataTable();

            parTbl.Columns.Add("name", typeof(String));

            parTbl.Columns.Add("cell_1", typeof(Decimal));
            parTbl.Columns.Add("cell_2", typeof(Decimal));
            parTbl.Columns.Add("cell_3", typeof(Decimal));
            parTbl.Columns.Add("cell_4", typeof(Decimal));

        }

        public static void MakeTbl3(ref DataTable parTbl)
        {

            if (parTbl == null)
                parTbl = new DataTable();

            parTbl.Columns.Add("name", typeof(String));

            parTbl.Columns.Add("cell_1_1", typeof(Decimal));
            parTbl.Columns.Add("cell_1_2", typeof(Decimal));
            parTbl.Columns.Add("cell_2_1", typeof(Decimal));
            parTbl.Columns.Add("cell_2_2", typeof(Decimal));
            parTbl.Columns.Add("cell_3_1", typeof(Decimal));
            parTbl.Columns.Add("cell_3_2", typeof(Decimal));
            parTbl.Columns.Add("cell_4_1", typeof(Decimal));
            parTbl.Columns.Add("cell_4_2", typeof(Decimal));
            parTbl.Columns.Add("cell_5_1", typeof(Decimal));
            parTbl.Columns.Add("cell_5_2", typeof(Decimal));
            parTbl.Columns.Add("cell_6_1", typeof(Decimal));
            parTbl.Columns.Add("cell_6_2", typeof(Decimal));
            parTbl.Columns.Add("cell_7_1", typeof(Decimal));
            parTbl.Columns.Add("cell_7_2", typeof(Decimal));
            parTbl.Columns.Add("cell_8_1", typeof(Decimal));
            parTbl.Columns.Add("cell_8_2", typeof(Decimal));

        }
    }
}
